package com.example.schooljava.controller;


import com.example.schooljava.annotation.RequestLimit;
import com.example.schooljava.pojo.dto.CurriculumDTO;
import com.example.schooljava.pojo.bo.CurriculumBO;
import com.example.schooljava.service.impl.CurriculumServiceImpl;
import com.example.schooljava.util.DTOtoBO;
import com.example.schooljava.util.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.ArrayList;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author LDH
 * @since 2022/08/11
 */
@RestController
@RequestMapping("/school/curriculum")
@RequestLimit(maxCount = 5,second = 2)
@Api(tags = "课程模块")
public class CurriculumController {
    @Autowired
    private CurriculumServiceImpl curriculumService;
    @Autowired
    private DTOtoBO dtOtoBO;

    @ApiOperation(value = "添加课程",notes = "<span style='color:red;'>详细描述：</span>&nbsp;添加一门课程，但不指定年级和班级")
    @PostMapping(name = "校长")
    public Result setCurriculum(@RequestBody @Valid CurriculumDTO curriculumDTO){
        CurriculumBO curriculumBO = new CurriculumBO();
        return curriculumService.setCurriculum((CurriculumBO) dtOtoBO.copyPro(curriculumDTO,curriculumBO));
    }

    @ApiOperation(value = "获取课程",notes = "<span style='color:red;'>详细描述：</span>&nbsp;获取所有课程信息")
    @PostMapping(value = "/getAll", name = "校长")
    public Result getCurriculum(@RequestBody CurriculumDTO curriculumDTO){
        CurriculumBO curriculumBO = new CurriculumBO();
        return curriculumService.getCurriculum((CurriculumBO) dtOtoBO.copyPro(curriculumDTO,curriculumBO));
    }

    @ApiOperation(value = "删除课程",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人员删除课程")
    @DeleteMapping(name = "校长")
    public Result delCurriculum(@RequestBody ArrayList<String> list){
        return curriculumService.delCurriculum(list);
    }

    @ApiOperation(value = "编辑课程",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人员修改课程信息")
    @PutMapping(name = "校长")
    public Result editCurriculum(@RequestBody @Valid CurriculumDTO curriculumDTO){
        CurriculumBO curriculumBO = new CurriculumBO();
        return curriculumService.editCurriculum((CurriculumBO) dtOtoBO.copyPro(curriculumDTO,curriculumBO));
    }

    @ApiOperation(value = "获取所有课程",notes = "<span style='color:red;'>详细描述：</span>&nbsp;学校管理人眼获取所有班级名称")
    @GetMapping("/getAllCurr")
    public Result getAllCurr(){
        return curriculumService.getAllCurr();
    }
}
